﻿
//----------------------------------------------==forSearch-----

function schQuick(value,name){
   if(0==value.length) {$.messager.show({title:mWTerOP,msg:'<span class="f14 spLRed">请输入关键字!</span><br><br><span class="spLBlue">注：快捷查询支持模糊搜索。</span>',iconCls:'icn-errB',timeout:2500,showType:'show',style:{left:'',right:0,top:document.body.scrollTop+document.documentElement.scrollTop,bottom:''}}); return false;}
   //alert('You input: ' + value+'('+name+')');
   $('#qxTGd').datagrid('clearSelections').datagrid("uncheckAll").datagrid('load',{schWay:'1',qxFld:name,schKey:value});
}

//----------------Senior-------------------

function snrFindCdtnShow(){
  var tabObj = document.getElementById("tabSnrCdtn");
  var tRs=tabObj.rows.length;
  var showStr = 'the condition';
  if(tRs<1) {
    showStr = '<br><span class="f14 spLRed">系统提示：您没有设置任何条件！</span>';
	$.messager.show({title:mWTerOP,msg:showStr,iconCls:'icn-errB',timeout:2000,showType:'fade',style:{right:'',bottom:''}});
  }
  else {
	  showStr = "";
	  for(var i=0;i<tRs;i++) {
		  var objFld = tabObj.rows[i].cells[0].childNodes[0];
          var objOP = tabObj.rows[i].cells[1].childNodes[0];
		  var objKey = tabObj.rows[i].cells[2].childNodes[0];
		  var objCnt = tabObj.rows[i].cells[4].childNodes[0];
		  showStr += objFld.options[objFld.selectedIndex].text +" <span class='spRed'>" +objOP.options[objOP.selectedIndex].text + "</span> <span class='spLBlue'>" + objKey.value + "</span> <span class='spOrange'>" +objCnt.options[objCnt.selectedIndex].text +"</span><br/><br/>";
     }
	 $.messager.alert('查询条件',showStr);
  }  
}

//--Clear the rows but the first one
function snrCdtnClear() {
  var tabObj = document.getElementById("tabSnrCdtn");
  var tRs=tabObj.rows.length;
  //alert(tRs);
  for(var i=0; i<tRs-1; i++) {
	 tabObj.deleteRow(0);
  }
  /**/
}


function snrCdtnOne() {
  var tabObj = document.getElementById("tabSnrCdtn");
  var tRs=tabObj.rows.length;
  if(tRs>0)
    return false;
  
  var nwRw = tabObj.insertRow(tRs);
  var clA  = nwRw.insertCell(0);
  var clB  = nwRw.insertCell(1);
  var clC  = nwRw.insertCell(2);
  var clD  = nwRw.insertCell(3);
  var clE  = nwRw.insertCell(4);
  
  var fldNames = "";
  $.each(cdtnsSnr, function (i, n) {fldNames+='<option value="'+n.field+'|'+n.fldPro+'">'+n.showText+'</option>';});
  clA.innerHTML="<select name=\"cdnField\">"+fldNames+"</select>";
  clA.height="28";
  
  var opStr = '<select name="cdnOper"><option value="201">包含</option><option value="101">等于</option><option value="202">不包括</option><option value="102">不等于</option><option value="120">大于</option><option value="110">小于</option></select>';
  clB.innerHTML = opStr;
  
  var keyIpt = '<input name="cdnKey" type="text" maxlength="30" />';
  clC.innerHTML = keyIpt;
  clC.align="left";
  
  var rmvBtn ='<img src="/images/snrDelCdtn.jpg" border=0 onClick="snrRemoveCdtn(this)" alt="移除此条件" />';
  //clD.innerHTML = "<input type=\"button\" onClick=\"snrRemoveCdtn(this)\" value=\"删除\" />";
  clD.innerHTML = rmvBtn;
  
  var cntDdl ='<select name="cdnCnt"><option value="and">并且</option><option value="or">或者</option></select>';
  clE.innerHTML = cntDdl;
}

//snrAddCdtn:the spare function
function snrAddCdtn(fpJson) {
  var tabObj = document.getElementById("tabSnrCdtn");
  var tRs=tabObj.rows.length;
  var nwRw = tabObj.insertRow(tRs);
  var clA  = nwRw.insertCell(0);
  var clB  = nwRw.insertCell(1);
  var clC  = nwRw.insertCell(2);
  var clD  = nwRw.insertCell(3);
  var clE  = nwRw.insertCell(4);
  
  var fldNames = ""; //fldPro(1=string,2=number,3=datetime)
  $.each(fpJson, function (i, n) {fldNames+='<option value="'+n.field+'|'+n.fldPro+'">'+n.showText+'</option>';});
  clA.innerHTML="<select name=\"cdnField\">"+fldNames+"</select>";
  clA.height="28";
  
  var opStr = '<select name="cdnOper"><option value="201">包含</option><option value="101">等于</option><option value="202">不包括</option><option value="102">不等于</option><option value="120">大于</option><option value="110">小于</option></select>';
  clB.innerHTML = opStr;
  
  var keyIpt = '<input name="cdnKey" type="text" maxlength="30" />';
  clC.innerHTML = keyIpt;
  clC.align="left";
  
  var rmvBtn ='<img src="/images/snrDelCdtn.jpg" border=0 onClick="snrRemoveCdtn(this)" alt="移除此条件" />';
  //clD.innerHTML = "<input type=\"button\" onClick=\"snrRemoveCdtn(this)\" value=\"删除\" />";
  clD.innerHTML = rmvBtn;
  
  var cntDdl ='<select name="cdnCnt"><option value="and">并且</option><option value="or">或者</option></select>';
  clE.innerHTML = cntDdl;
}

function snrRemoveCdtn(e) {
  var rIdx = e.parentNode.parentNode.rowIndex;
  //alert(rIdx);
  document.getElementById("tabSnrCdtn").deleteRow(rIdx);
}


function snrExeSearch(){
  var tabObj = document.getElementById("tabSnrCdtn");
  var tRs=tabObj.rows.length;
  var showStr = 'goto Search';
  var canSch = false;
  
  if(tRs<1) {
    showStr = '<br><span class="f14 spLRed">您没有设置任何条件！</span>';
	$.messager.show({title:mWTerOP,msg:showStr,iconCls:'icn-errB',timeout:2000,showType:'fade',style:{right:'',bottom:''}});
	return false;
  }
  else {
	  showStr='<br><span class="f14 spLRed">您没有设置有效的查询条件！</span>';
	  //var fldName = 'none';
	  //var opName = 'none';
	  //var keyVal = '';
	  //var cnntName = "none";
	  var jsonStr = "[]";
	  var tmpJson ="";
	  
	  for(var i=0;i<tRs;i++) {
		  var objFld = tabObj.rows[i].cells[0].childNodes[0];
          var objOP = tabObj.rows[i].cells[1].childNodes[0];
		  var objKey = tabObj.rows[i].cells[2].childNodes[0];
		  var objCnt = tabObj.rows[i].cells[4].childNodes[0];
		  //construct the parameter
		  var tmpKey = objKey.value.Trim();
		  if(tmpKey.length>0) {
			  canSch = true;
			  //alert(tmpKey);
			  tmpJson += '{fdName:"'+objFld.options[objFld.selectedIndex].value+'",opFlag:"'+objOP.options[objOP.selectedIndex].value+'",kyVla:"'+ tmpKey +'",lnkFlag:"'+objCnt.options[objCnt.selectedIndex].value+'"},';
		  }
     }
	 //--cut the last Character
	 if(tmpJson.length>2) tmpJson = tmpJson.substr(0,tmpJson.length-1);
	 jsonStr = "["+tmpJson+"]";
  }
  
  if(canSch) {
	 //$.messager.alert('testMsg',jsonStr,'info');
     $('#qxTGd').datagrid('clearSelections').datagrid("uncheckAll").datagrid('load',{schWay:'3',cdtnJson:jsonStr});
  }
  else {
	$.messager.show({title:mWTerOP,msg:showStr,iconCls:'icn-errB',timeout:2500,showType:'fade',style:{right:'',bottom:''}});
  }
}
//----------------------------------------------forSearch==-----

//-------------------------------------------==forToolBar-----

function QxGridReload(gridId) {
  $("#"+gridId+"").datagrid('clearSelections').datagrid("uncheckAll").datagrid("reload");
}
function EvtWhenCloseQxWin(gridId){
   if("0"!=$("#hdIfFresh").val()) {QxGridReload(gridId);}
}

//click then show the detail
function fmtToClickShow(value,row,index){
    var pk = row.myPkVal;
	return '<a href="javascript:void(0);" onclick="OnQxListShowWin(\''+pk+'\')" title="点击浏览详情">'+value+'</a>';
}

//=====CRUD====
function LogicAdd() {
   OnQxListEditWin(0,-1);
}

function LogicEdit(gridId) {
   var row = $('#'+gridId+'').datagrid('getSelected');
	if(row) {
	  //alert(row.myPkVal);
	  var sltVal = row.myPkVal;
	  return sltVal;
	}
	else {
	   //alert(row);
	   $.messager.show({title:mWTerOP,msg:mCClwEdit,iconCls:'icn-errB',timeout:3000,showType:'fade',style:{right:'',left:10,top:document.body.scrollTop+document.documentElement.scrollTop+80,bottom:''}});
	   return null;
	}
}

function LogicDeal(gridId) {
	   var row = $('#'+gridId+'').datagrid('getSelected');   
		if(row) {
		  //alert(row.myPkVal);
		  var sltVal = row.myPkVal;
		  return sltVal;
		}
		else {
		   //alert(row);
		   $.messager.show({title:mWTerOP,msg:mCClwDeal,iconCls:'icn-errB',timeout:3000,showType:'fade',style:{right:'',left:10,top:document.body.scrollTop+document.documentElement.scrollTop+80,bottom:''}});
		   return null;
		}
}

function LogicPrint(gridId) {
	var rowS = $('#'+gridId+'').datagrid('getSelections');
	   if(rowS.length<1) {
		   $.messager.show({title:mWTerOP,msg:"请选中要打印的项",iconCls:'icn-errB',timeout:2000,showType:'fade',style:{right:'',left:10,top:document.body.scrollTop+document.documentElement.scrollTop+80,bottom:''}});
		   return null;
	   }
	   var valS = "";
	   for(var i=0; i<rowS.length; i++){
		  valS += rowS[i].myPkVal + ",";
	   }
	   valS = valS.substr(0,valS.length-1);
	return valS;
}

function LogicScan(gridId) {
   var row = $('#'+gridId+'').datagrid('getSelected');   
	if(row) {
	  var sltVal = row.myPkVal;
	  return sltVal;
	}
	else {
	   $.messager.show({title:mWTerOP,msg:mCClwShow,iconCls:'icn-errB',timeout:3000,showType:'fade',style:{right:'',left:10,top:document.body.scrollTop+document.documentElement.scrollTop+80,bottom:''}});
	   return null;
	}
}

function LogicOP(gridId) {
   var rowS = $('#'+gridId+'').datagrid('getSelections');
   if(rowS.length<1) {
	   $.messager.show({title:mWTerOP,msg:mCClwOP,iconCls:'icn-errB',timeout:3000,showType:'fade',style:{right:'',left:10,top:document.body.scrollTop+document.documentElement.scrollTop+80,bottom:''}});
	   return null;
   }
   
   var valS = "";
   for(var i=0; i<rowS.length; i++){
	  valS += rowS[i].myPkVal + ",";
   }
   valS = valS.substr(0,valS.length-1);
   return valS;
}

//========delete=======
function delMsgSysErr() {
	$.messager.show({title:mWTError,msg:mCErrSys,iconCls:'icn-errB',timeout:2000,showType:'fade',style:{right:'',bottom:''} });
}
function delMsgOpFaild() {
	$.messager.show({title:mWTSys,msg:mCDelFaild,iconCls:'icon-tip',timeout:3000,showType:'fade',style:{right:'',bottom:''} });
}
function delMsgOpOK() {
	$.messager.show({title:mWTSys,msg:mCDelSucc,iconCls:'icon-tip',timeout:3000,showType:'fade',style:{right:'',bottom:''} });
}
function LogicDel(gridId) {
   var rowS = $('#'+gridId+'').datagrid('getSelections');
   if(rowS.length<1) {
	   $.messager.show({title:mWTerOP,msg:mCClwDel,iconCls:'icn-errB',timeout:3000,showType:'fade',style:{right:'',left:10,top:document.body.scrollTop+document.documentElement.scrollTop+80,bottom:''}});
	   return null;
   }
   //var ids = [];
   var valS = "";
   for(var i=0; i<rowS.length; i++){  
      //ids.push(rowS[i].myPkVal);
	  valS += rowS[i].myPkVal + ",";
   }  
   //alert(ids.join('\n'));
   valS = valS.substr(0,valS.length-1);
   return valS;
}

function empyMsgSysErr() {
	$.messager.show({title:mWTError,msg:mCErrSys,iconCls:'icn-errB',timeout:2000,showType:'fade',style:{right:'',bottom:''} });
}
function empyMsgOpFaild() {
	$.messager.show({title:mWTSys,msg:mCempFaild,iconCls:'icon-tip',timeout:3000,showType:'fade',style:{right:'',bottom:''} });
}
function empyMsgOpOK() {
	$.messager.show({title:mWTSys,msg:mCempSucc,iconCls:'icon-tip',timeout:3000,showType:'fade',style:{right:'',bottom:''} });
}

function bthMsgSysErr() {
	$.messager.show({title:mWTError,msg:mCErrSys,iconCls:'icn-errB',timeout:2000,showType:'fade',style:{right:'',bottom:''} });
}
function bthMsgOpFaild() {
	$.messager.show({title:mWTSys,msg:mCBthFaild,iconCls:'icon-tip',timeout:3000,showType:'fade',style:{right:'',bottom:''} });
}
function bthMsgOpOK() {
	$.messager.show({title:mWTSys,msg:mCBthSucc,iconCls:'icon-tip',timeout:3000,showType:'fade',style:{right:'',bottom:''} });
}
//-------------------------------------------forToolBar==-----

//-------------------------------==for DataGrid-----

function fmtsysYesNo(value,row,index){
    var rtn = value;
    var myVal = parseInt(value);
    switch (myVal) {
      case 0:
    	  rtn = '<div class="spBlue">否</div>';
    	break;
      case 1:
    	  rtn = '<div class="spRed">是</div>';
    	break;

      default:
    	  break;
    }
	return rtn;
}

function fmtsysIssue(value,row,index){
    var rtn = value;
    var myVal = parseInt(value);
    switch (myVal) {
      case 0:
    	  rtn = '<div class="spBlue">否</div>';
    	break;
      case 1:
    	  rtn = '<div class="spRed">是</div>';
    	break;

      default:
    	  break;
    }
	return rtn;
}
//-----end Sys

function fmtTelGetState(value,row,index){
    var rtn = value;
    var myVal = parseInt(value);
    switch (myVal) {
      case 101:
    	  rtn = '<div class="spDGray">草稿</div>';
    	break;
      case 120:
    	  rtn = '<div class="spOrange">转后台</div>';
    	break;
      case 121:
    	  rtn = '<div class="spOrange">退回坐席</div>';
    	break;
      case 122:
    	  rtn = '<div class="spLBlue">后台处理中</div>';
    	break;
      case 125:
    	  rtn = '<div class="spBlue">生成工单</div>';
    	break;
      case 131:
    	  rtn = '<div class="spLBlue">话务员办结</div>';
    	break;
      case 132:
    	  rtn = '<div class="spLRed">无效来电</div>';
    	break;
      case 135:
    	  rtn = '<div class="spLRed">值班长作废</div>';
    	break;
      case 136:
    	  rtn = '<div class="spLBlue">值班长办结</div>';
    	break;
    	
      default:
    	  break;
    }
	return rtn;
}



function fmtWFormSort(value,row,index){
    var rtn = value;
    var myVal = parseInt(value);
    switch (myVal) {
      case 11:
    	  rtn = '<div class="spLDark">普通</div>';
    	break;
      case 21:
    	  rtn = '<div class="spOrange">督办</div>';
    	break;
      case 31:
    	  rtn = '<div class="spRed">呈批</div>';
    	break;
    	
      default:
    	  break;
    }
	return rtn;
}
function fmtWFormOpen(value,row,index){
    var rtn = value;
    var myVal = parseInt(value);
    switch (myVal) {
      case 0:
    	  rtn = '<div class="spLDark">否</div>';
    	break;
      case 1:
    	  rtn = '<div class="spRed">是</div>';
    	break;

      default:
    	  break;
    }
	return rtn;
}



function fmtSBSendState(value,row,index){
    var rtn = value;
    var myVal = parseInt(value);
    switch (myVal) {
        case 0:
            rtn = '<div>none</div>';
            break;
        case 10:
            rtn = '<div class="spRed">未签收</div>';
            break;
        case 11:
            rtn = '<div class="spOrange">再次派单</div>';
            break;

        case 21:
            rtn = '<div class="spBlue">已签收</div>';
            break;
        case 22:
            rtn = '<div class="spOrange">已签(派下级)</div>';
            break;
        case 23:
            rtn = '<div class="spBlue">已签(派下级)</div>';
            break;

        case 30:
            rtn = '<div class="spOrange">撤回</div>';
            break;
        case 40:
            rtn = '<div class="spRed">退回</div>';
            break;
        case 51:
            rtn = '<div class="spRed">拒退</div>';
            break;

        default:
            break;
    }
    return rtn;
}
function fmtSBBackState(value,row,index){
    var rtn = value;
    var myVal = parseInt(value);
    switch (myVal) {
      case 0:
    	  rtn = '<div class="spRed">未回复</div>';
    	break;
      case 10:
    	  rtn = '<div class="spLRed">已回(未审)</div>';
    	break;
    	
      case 11:
    	  rtn = '<div class="spLBlue">已回(已审)</div>';
    	break;
      case 12:
    	  rtn = '<div class="spRed">本级不通过</div>';
    	break;
    	
      case 21:
    	  rtn = '<div class="spBlue">上级通过</div>';
    	break;
      case 22:
    	  rtn = '<div class="spRed">上级不通过</div>';
    	break;

      default:
    	  break;
    }
	return rtn;
}
function fmtSBBackCheck(value,row,index){
    var rtn = value;
    var myVal = parseInt(value);
    switch (myVal) {
      case 0:
    	  rtn = '<div>-</div>';
    	break;
      case 10:
    	  rtn = '<div class="spLRed">未审</div>';
    	break;
    	
      case 11:
    	  rtn = '<div class="spLBlue">自审通过</div>';
    	break;
      case 12:
    	  rtn = '<div class="spRed">自审不通过</div>';
    	break;
    	
      case 21:
    	  rtn = '<div class="spBlue">上级通过</div>';
    	break;
      case 22:
    	  rtn = '<div class="spRed">上级不通过</div>';
    	break;

      default:
    	  rtn = '<div></div>';
    	  break;
    }
	return rtn;
}


function fmtDeferState(value,row,index){
    var rtn = value;
    var myVal = parseInt(value);
    switch (myVal) {
      case 0:
    	  rtn = '<div class="spRed">none</div>';
    	break;
    	
      case 10:
    	  rtn = '<div class="spLRed">待审核</div>';
    	break;
    	
      case 21:
    	  rtn = '<div class="spBlue">同意</div>';
    	break;
      case 22:
    	  rtn = '<div class="spRed">不同意</div>';
    	break;

      default:
    	  break;
    }
	return rtn;
}


function fmtVisitFlag(value,row,index){
    var rtn = value; //VstJudgeCtrl
    var myVal = parseInt(value);
    switch (myVal) {
      case 0:
    	  rtn = '<div class="spRed">none</div>';
    	break;
    	
      case 21:
    	  rtn = '<div class="spLRed">不满意</div>';
    	break;
      case 22:
    	  rtn = '<div class="spBlue">评价满意</div>';
    	break;
      case 25:
    	  rtn = '<div class="spRed">回访失败</div>';
    	break;

      default:
    	  rtn = '<div class="spRed">none</div>';
    	  break;
    }
	return rtn;
}

function fmtRecordFlag(value,row,index){
    var rtn = value; //VstJudgeCtrl
    var myVal = parseInt(value);
    switch (myVal) {
      case 0:
    	  rtn = '<div class="spRed">none</div>';
    	break;
    	
      case 20:
    	  rtn = '<div class="spLRed">未归档</div>';
    	break;
      case 21:
    	  rtn = '<div class="spLBlue">自动</div>';
    	break;
      case 22:
    	  rtn = '<div class="spBlue">归档</div>';
    	break;
      case 29:
    	  rtn = '<div class="spRed">强制</div>';
    	break;

      default:
    	  rtn = '<div class="spRed">none</div>';
    	  break;
    }
	return rtn;
}
//-------------------------------for DataGrid==-----